package org.openea.eap.module.obpm.service.singlelogin.util;

import cn.hutool.core.codec.Base64;
import org.openea.eap.module.obpm.service.singlelogin.config.ApiConfiguration;

import java.util.HashMap;
import java.util.Map;

public class HttpHeadersUtil {
    public static Map<String, String> createHeaders(ApiConfiguration apiConfig) {
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        headers.put("Authorization", "Basic " + getEncodedCredentials(apiConfig));
        return headers;
    }

    private static String getEncodedCredentials(ApiConfiguration apiConfig) {
        String credentials = apiConfig.getClientAppCode() + ":" + apiConfig.getInterfaceAccount() + ":" + apiConfig.getInterfacePassword();
        return Base64.encode(credentials);
    }
}
